<%@page contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.cndatacom.teleweb.util.*" %>
<%@page import="java.io.*"%>
<%@page import="java.awt.*" %>
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<%@page import="javax.imageio.ImageIO" %>

<% 
	//获取数据库连接---
	Connection conn = null;
	Statement stmt = null;
	
	String driverClassName = "oracle.jdbc.driver.OracleDriver";
	String url = "jdbc:oracle:thin:@localhost:1521:orcl";
	String userName = "ccseweb";
	String password = "password";
	try {
		Class.forName(driverClassName);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	
	java.util.List list = new ArrayList();
	
	try {
		conn = DriverManager.getConnection(url, userName, password);
		stmt = conn.createStatement();
		
		String webPath = request.getRealPath("/");
		String folderPath = webPath + "pictemp";//缩略图所在的文件夹路劲
		File f = new File(folderPath);
		boolean isDir = f.isDirectory();
		if(!isDir){//目录不存在则先建目录
			try{
				f.mkdirs();
			}catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		File[] files = FileUtil.getFoldFileList(webPath + "resizeimages");
		
		String pic_path = "";
		String minipic_path = "";
		
		for(int i=0; i<files.length; i++) {
			Boolean b = true;
			File file = files[i];
			String fileName = file.getName();//指定文件夹下的图片名字
			String fromPath = file.getAbsolutePath();
			
			String toPath = folderPath + "/" + fileName;
			pic_path = "resizeimages/" + fileName;
			minipic_path = "pictemp/" + fileName;
			
			File[] filesTemps = FileUtil.getFoldFileList(folderPath);
			for(int j=0;j<filesTemps.length;j++) {
				File filesTemp = filesTemps[j];
				String fileTempName = filesTemp.getName();
				if(fileTempName.equals(fileName)) {
					b = false;
					break;
				}
			}
			
			if(b) {
				new CreatePreviewImageUtil().saveImageAsJpg(fromPath,toPath,140,140);
				String picSQL = "insert into vote_picinfo (pic_path,minipic_path) values ('"+pic_path+"','"+minipic_path+"')";//插入图片信息的SQL语句，插入原图相对路劲和缩略图的相对路劲
				stmt.executeUpdate(picSQL);
			}
			list.add(toPath);
			
		}
		
	}catch (SQLException e) {
		e.printStackTrace();
	}finally {
		stmt.close();
		conn.close();
	}

%>

<html>
	<head>
		<title>用户登陆</title>
	</head>
	
	<% 
		for(int n=0; n<list.size(); n++) {
			String src = (String)list.get(n);
			src = src.substring(src.indexOf("pictemp"));
	%>
		<img alt="image" src="../<%=src %>">
	<%
		}
	%>
	
	<body>
		<center>
		<h3>请输入用户名和密码来登陆</h3>
		如果还没有注册，单击此处<a href="requestPage?page=regist">注册</a>&nbsp;&nbsp;&nbsp;<a href="user-list">列表</a><br/>
		<a href="excel">Excel</a>
		<s:fielderror />
		<s:actionerror/>
		<s:form action="admin-login" method="post">
			<s:textfield name="user.account" label="用户名"/><br />
			<s:password name="user.password" label="密码"/><br />
			<s:submit value="登陆"/>
		</s:form>
		</center>
	</body>
</html>